@charset "utf-8";

// 定义浮层tip的基础构造
@mixin _tip {
    position: fixed;
    min-width: 1rem;
    max-width: 90%;
    z-index: map-get($z-index, tip);
    padding: map-get($tip, padding);
    border-radius: map-get($tip, radius);
    background-color: map-get($tip, bgcolor);
    color: map-get($tip, color);
    text-align: center;
    > .arrow {
        position: absolute;
        content: "\0020";
        border-width: map-get($tip, arrow-size);
        border-style: solid;
        border-color: transparent;
        &-top {
            top: -#{map-get($tip, arrow-size) * 2};
            border-bottom-color: map-get($tip, bgcolor);
        }
        &-right {
            right: -#{map-get($tip, arrow-size) * 2};
            border-left-color: map-get($tip, bgcolor);
        }
        &-bottom {
            bottom: -#{map-get($tip, arrow-size) * 2};
            border-top-color: map-get($tip, bgcolor);
        }
        &-left {
            left: -#{map-get($tip, arrow-size) * 2};
            border-right-color: map-get($tip, bgcolor);
        }
    }
}

/**
 * @module widget
 * @method yo-tip
 * @version 1.0.0
 * @description 构造列表的自定义使用方法
 * @demo http://doyoe.github.io/Yo/demo/widget/yo-tip.html
 * @param {String} $name 定义扩展名称 <1.0.0>
 * @param {Length} $padding 内补白 <1.0.0>
 * @param {Length} $radius 圆角半径长度 <1.0.0>
 * @param {Color} $bgcolor 背景色 <1.0.0>
 * @param {Color} $color 文本色 <1.0.0>
 * @param {Length} $arrow-size 箭头大小 <2.1.1>
 */

@mixin yo-tip(
    $name: default,
    $padding: default,
    $radius: default,
    $bgcolor: default,
    $color: default,
    $arrow-size: default) {
    // 区别是否新增实例还是修改本身
    $name: if($name == default, "", "-#{$name}");
    // 如果值为default，则取config的定义
    @if $padding == default {
        $padding: map-get($tip, padding);
    }
    @if $radius == default {
        $radius: map-get($tip, radius);
    }
    @if $bgcolor == default {
        $bgcolor: map-get($tip, bgcolor);
    }
    @if $color == default {
        $color: map-get($tip, color);
    }
    @if $arrow-size == default {
        $arrow-size: map-get($tip, arrow-size);
    }
    .yo-tip#{$name} {
        @if $padding != map-get($tip, padding) {
            padding: $padding;
        }
        @if $radius != map-get($tip, radius) {
            border-radius: $radius;
        }
        @if $bgcolor != map-get($tip, bgcolor) {
            background-color: $bgcolor;
        }
        @if $color != map-get($tip, color) {
            color: $color;
        }
        > .arrow {
            @if $arrow-size != map-get($tip, arrow-size) {
                border-width: $arrow-size;
            }
            &-top {
                @if $arrow-size != map-get($tip, arrow-size) {
                    top: -#{$arrow-size * 2};
                }
                @if $bgcolor != map-get($tip, bgcolor) {
                    border-bottom-color: $bgcolor;
                }
            }
            &-right {
                @if $arrow-size != map-get($tip, arrow-size) {
                    right: -#{$arrow-size * 2};
                }
                @if $bgcolor != map-get($tip, bgcolor) {
                    border-left-color: $bgcolor;
                }
            }
            &-bottom {
                @if $arrow-size != map-get($tip, arrow-size) {
                    bottom: -#{$arrow-size * 2};
                }
                @if $bgcolor != map-get($tip, bgcolor) {
                    border-top-color: $bgcolor;
                }
            }
            &-left {
                @if $arrow-size != map-get($tip, arrow-size) {
                    left: -#{$arrow-size * 2};
                }
                @if $bgcolor != map-get($tip, bgcolor) {
                    border-right-color: $bgcolor;
                }
            }
        }
        // 增量扩展
        @content;
    }
}

// 调用本文件时载入tip基础构造
.yo-tip {
    @include _tip;
}